package com.tianci.appstore.ui.list;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.tianci.appstore.R;
import com.tianci.appstore.audio.IAudio;
import com.tianci.appstore.ui.SkinManager;
import com.tianci.appstore.ui.loading.LoadingView;
import com.tianci.appstore.ui.util.UICommon;
import com.tianci.appstore.utils.SkyConstants;

public abstract class ListBaseView extends FrameLayout {
    protected FrameLayout contentLayout;
    protected LoadingView loadingView;
    protected TextView tipText;
    protected boolean hideStartupApp = false;

    public ListBaseView(Context context) {
        super(context);
        //hideStartupApp = SkyGeneralProperties.getBoolProperty("NEW_BOOT_FLOW");
        contentLayout = new FrameLayout(context);
        this.addView(contentLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

        loadingView = new LoadingView(context);
        this.addView(loadingView, new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT));
        loadingView.setVisibility(View.INVISIBLE);

        tipText = UICommon.newTextView(context, UICommon.tipTextSize, R.color.tipColor);
        tipText.setCompoundDrawablePadding(SkyConstants.Div(18));
        tipText.setCompoundDrawablesWithIntrinsicBounds(SkinManager.getResDrawable(R.drawable.cart_icon), null, null, null);
        this.addView(tipText, new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT, Gravity.CENTER));
        tipText.setVisibility(View.INVISIBLE);
    }

    public abstract void destroyController();

    public abstract void resume();

    public boolean processKeyDown(int keyCode) {
        return false;
    }

    public void setLoadingVisible(boolean visible) {
        if (visible) {
            contentLayout.setVisibility(View.INVISIBLE);
            loadingView.startLoading();
        } else {
            loadingView.stopLoading();
            contentLayout.setVisibility(View.VISIBLE);
        }
    }

    public void setEmptyTipVisible(boolean visible, String tipString) {
        if (visible) {
            loadingView.stopLoading();
            contentLayout.setVisibility(View.GONE);
            tipText.setText(tipString);
            tipText.setVisibility(View.VISIBLE);
        } else {
            tipText.setVisibility(View.INVISIBLE);
            contentLayout.setVisibility(View.VISIBLE);
        }
    }

    public abstract IAudio getAudioInterface();
}
